<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // 处理数组中最大值
    const arr = [10,20,30,50,60,100,20,70];

    // es5写法
    console.log(Math.max.apply(arr));

    //es6写法
    // 扩展运算符：将一个数组分割，并将各个项作为分离的参数传给函数
    console.log(Math.max(...arr));


    // es6箭头函数
    // 使用“=>”来定义，function(){} 等价于 () => {}

    // es5写法
    let add = function (a,b){
        return a + b
    }
    console.log(add(10,20));

    // es6写法
    let add2 = (a,b) => {
        return a + b;
    }
    console.log(add2(10,20));

    // 简洁写法
    let add3 = val => val;

    let add4 = val => val + 3;

    let add5 = (a,b) => a + b;

    let add6 = () => 'hello' + 1;


    // es5写法
    let fn = (function (){
        return function (){
            console.log('hello');
        }
    })();
    fn();

    let fn2 = (()=>{
        return () => {
            console.log('hello es6');
        }
    })();
    fn2();
</script>
</body>
</html>